<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ page import="entity.Owner" %>
        <%@ page import="java.text.SimpleDateFormat" %>
            <%@ page import="java.util.Date" %>

                <html>

                <head>
                    <title>编辑业主信息</title>
                    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
                        rel="stylesheet">
                    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css"
                        rel="stylesheet">
                    <style>
                        body {
                            background-color: #f8f9fa;
                            padding-top: 2rem;
                        }

                        .container {
                            max-width: 800px;
                        }
                    </style>
                </head>

                <body class="bg-light">
                    <% Owner owner=(Owner) request.getAttribute("owner"); SimpleDateFormat sdf=new
                        SimpleDateFormat("yyyy-MM-dd"); String dateStr="" ; if (owner.getCreateTime() !=null) {
                        dateStr=sdf.format(owner.getCreateTime()); } %>
                        <div class="container mt-4">
                            <div class="d-flex align-items-center mb-4">
                                <a href="ownerManage.jsp" class="btn btn-outline-secondary me-3">
                                    <i class="bi bi-arrow-left"></i> 返回
                                </a>
                                <h2>编辑业主信息</h2>
                            </div>

                            <div class="card">
                                <div class="card-body">
                                    <form action="${pageContext.request.contextPath}/admin/owner/update" method="post">
                                        <input type="hidden" name="id" value="<%= owner.getId() %>">

                                        <div class="mb-3">
                                            <label class="form-label">用户名</label>
                                            <input type="text" class="form-control" name="username"
                                                value="<%= owner.getUsername() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">密码</label>
                                            <input type="password" class="form-control" name="password"
                                                value="<%= owner.getPassword() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">姓名</label>
                                            <input type="text" class="form-control" name="name"
                                                value="<%= owner.getName() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">楼号</label>
                                            <input type="text" class="form-control" name="building"
                                                value="<%= owner.getBuilding() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">单元</label>
                                            <input type="text" class="form-control" name="unit"
                                                value="<%= owner.getUnit() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">房间号</label>
                                            <input type="text" class="form-control" name="roomNumber"
                                                value="<%= owner.getRoom() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">类型</label>
                                            <select class="form-select" name="type" required>
                                                <option value="1" <%=owner.getType().equals("1") ? "selected" : "" %>>业主
                                                </option>
                                                <option value="2" <%=owner.getType().equals("2") ? "selected" : "" %>>租户
                                                </option>
                                            </select>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">车牌号</label>
                                            <input type="text" class="form-control" name="plateNumber"
                                                value="<%= owner.getPlateNumber() %>">
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">联系电话</label>
                                            <input type="tel" class="form-control" name="phone"
                                                value="<%= owner.getPhone() %>" required>
                                        </div>

                                        <div class="mb-3">
                                            <label class="form-label">入住时间</label>
                                            <input type="date" class="form-control" name="checkInDate"
                                                value="<%= dateStr %>" required>
                                        </div>

                                        <div class="text-end">
                                            <button type="button" class="btn btn-secondary me-2"
                                                onclick="history.back()">取消</button>
                                            <button type="submit" class="btn btn-primary">保存修改</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>

                        <script
                            src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
                </body>

                </html>